<?php

if(getInput("newRow", false)){
	$params = $_REQUEST;
}

$name = getInputArray("name", $params,'');
$view = getInputArray("view", $params,'');
$counter = getInputArray("counter", $params, 0);
$values = getInputArray("value", $params,array());
$uniqueId = str_replace(".","",str_replace(" ","",microtime()));
$addMoreText = getInputArray("addMoreText", $params,'');

//new empty value to enter
$values[] = new stdClass();
$values[sizeof($values)-1]->value = "";
$values[sizeof($values)-1]->id = "";
?>
 
<?php

// all the actual values
foreach($values as $value){
	$params["value"] = $value->value;
	$params["name"] = $name . $counter;
	$params["counter"] = $counter;
	$uniqueIdToDelete = $params["name"];
	$newParams = $params;
	$newParams["id"] = $uniqueIdToDelete;
	echo "<div id='$uniqueIdToDelete' class='multipleValuesOption'>";
	echo "<input type='hidden' name='".$name."_id$counter' id='".$name."_id$counter' value='".$value->id."'></input>";
	echo "<div class='multipleValuesLeft'>";
	echo loadView($view, $newParams);
	echo "</div>";
	echo "<div class='multipleValuesRight'>";
	echo "<a href='#$uniqueIdToDelete' onclick='showHide(\"" . $uniqueIdToDelete . "\"); emtpyValue(\"" . $newParams["idEmtpyValue"] . $counter . "\")' title='".langEcho("delete")."' class='deleteInfoIcon'>X " . langEcho("delete") . "</a>";
	echo "</div>";
	echo "</div>";
	$counter++;
}

// for the javascript
$params["name"] = $name;
$params["counter"] = $counter;
$querystring = "?newRow=true";
foreach($params as $key => $value){
	if(is_array($value)){
		foreach($value as $key2 => $value2){			
			$querystring.= "&" . $key . "[" . $key2. "]=". urlencode($value2);
		}
	}else{
		$querystring.= "&" . $key . "=" . urlencode($value);
	} 	
}
?>
	<div id="<?php echo $uniqueId?>" class="addInfoIcon">
		<a href="<?php echo "#".$uniqueId?>" onclick="$('#<?php echo $uniqueId?>').load('<?php echo WWWROOT . "views/input/multipleValues.php" . $querystring ?>'); return false;" title="<?php echo $addMoreText;?>" class="addInfoIconA">+ <?php echo $addMoreText;?></a>
		<?php
		echo "<input type='hidden' name='" . $name . "Counter' value='". $counter . "' />";
		?>
	</div>
